import {LOGIN_TYPE,LOGOUT_TYPE} from "../actions/user"
let userInfo = localStorage.getItem("userInfo");
try {
    userInfo=JSON.parse(userInfo)||{}
} catch (err) {
    userInfo={}
}

let initial = {
    userInfo
}
let reducer = function (state = initial, action) {
    let newstate=state
    switch (action.type) {
        case LOGIN_TYPE: newstate = { userInfo: action.payload }
        console.log("paylode",action.payload);
            localStorage.setItem("userInfo",JSON.stringify(action.payload))
            return newstate;
        case LOGOUT_TYPE: newstate = { userInfo: {} }
            localStorage.removeItem("userInfo")
            return newstate
        default: return newstate
    }
}

export default reducer